﻿#region Using Statements
using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Xna.Framework;
using System.Runtime.InteropServices;
#endregion

#region COPYRIGHT

/*
    Copyright (c) 2008, 2009, 2010 
        Roland Rosenkranz (Glatzemann@email.de)
*/

#endregion

#region LICENSE

/*
    This file is part of starLiGHT.Collision.

    starLiGHT.Collision is free software: you can redistribute it and/or modify
    it under the terms of the GNU Lesser General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    starLiGHT.Collision is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public License
    along with starLiGHT.Collision.  If not, see <http://www.gnu.org/licenses/>.

    
    ADDITIONAL (commercial) LICENSES for starLiGHT.Collision are available on request.
*/

#endregion

#region Box2D Copyright
/*
* Copyright (c) 2006-2009 Erin Catto http://www.gphysics.com
*
* This software is provided 'as-is', without any express or implied
* warranty.  In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#endregion

#region Version Stuff
// **************[ starLiGHT.Engine SVN ]**********************
// * $Rev:: 1486                  $:  Revision of last commit *
// * $Author:: glatzemann         $:  Author of last commit   *
// * $Date:: 2010-10-08 15:55:47 #$:  Date of last commit     *
// ************************************************************

// **************[ Box2D-Repository Info ]*********************
// Header-File: http://code.google.com/p/box2d/source/diff?spec=svn33&r=33&format=side&path=/trunk/Box2D/Box2D/Common/b2Settings.h
// Revision   : r69
// Change-Date: 2010-03-23
//
// Source-File: http://code.google.com/p/box2d/source/diff?spec=svn33&r=33&format=side&path=/trunk/Box2D/Box2D/Common/b2Settings.cpp
// Revision   : r33
// Change-Date: 2010-01-25
//
// Status     : Finished! CHECK AGAIN!!!
#endregion

////////TODO: see status!

namespace starLiGHT.Physic.TwoD
{
    public static class PhysicSettings
    {
        // SPH Constants. These are used for fluid simulation (Blaze)
        // comes from: http://www.dsource.org/projects/blaze/browser/trunk/blaze/common/bzConstants.d
        public static readonly float DENSITY_OFFSET = 100f;
        public static readonly float GAS_CONSTANT = 0.1f;
        public static readonly float VISCOSITY = 0.002f;
        public static readonly float CELL_SPACE = 15.0f / 64.0f;

        public static readonly float FLT_EPSILON = 1.192092896e-07F;//smallest such that 1.0f+FLT_EPSILON != 1.0f 
        public static readonly float FLT_EPSILON_SQUARED = FLT_EPSILON * FLT_EPSILON;//smallest such that 1.0f+FLT_EPSILON != 1.0f 
        public static readonly float FLT_MAX = 3.402823466e+38F;
        public static float FORCE_SCALE(float x) { return x; }
        public static float FORCE_INV_SCALE(float x) { return x; }
 
        public static readonly float b2_pi = 3.14159265359f;

        // Global tuning constants based on meters-kilograms-seconds (MKS) units. 

        /// The maximum number of contact points between two convex shapes. 
        public static readonly int MaxManifoldPoints = 2;

        /// The maximum number of vertices on a convex polygon. 
        public static readonly int MaxPolygonVertices = 8;

        /// This is used to fatten AABBs in the dynamic tree. This allows proxies
        /// to move by a small amount without triggering a tree adjustment.
        /// This is in meters.
        public static float aabbExtension = 0.1f;

        /// This is used to fatten AABBs in the dynamic tree. This is used to predict 
        /// the future position based on the current displacement. 
        /// This is a dimensionless multiplier. 
        public static float aabbMultiplier = 2.0f;

        /// <summary> 
        /// A small length used as a collision and constraint tolerance. Usually it is 
        /// chosen to be numerically significant, but visually insignificant. 
        /// </summary> 
        public const float LinearSlop = 0.005f;       // 0.5 cm 

        /// <summary> 
        /// A small angle used as a collision and constraint tolerance. Usually it is 
        /// chosen to be numerically significant, but visually insignificant. 
        /// </summary> 
        public static readonly float AngularSlop = 2.0f / 180.0f * b2_pi; // 2 degrees 

        /// <summary> 
        /// The radius of the polygon/edge shape skin. This should not be modified. Making 
        /// this smaller means polygons will have and insufficient for continuous collision. 
        /// Making it larger may create artifacts for vertex collision. 
        /// </summary> 
        public static readonly float PolygonRadius = 2.0f * LinearSlop;

        /// <summary>
        /// Maximum number of sub-steps per contact in continuous physics simulation.
        /// </summary>
        public static readonly int MaxSubSteps = 8;

        /// <summary> 
        /// Maximum number of contacts to be handled to solve a TOI impact. 
        /// </summary> 
        public static readonly int MaxTOIContacts = 32;

        /// <summary> 
        /// A velocity threshold for elastic collisions. Any collision with a relative linear 
        /// velocity below this threshold will be treated as inelastic. 
        /// </summary> 
        public static readonly float VelocityThreshold = 1.0f; // 1 m/s 

        /// <summary> 
        /// The maximum linear position correction used when solving constraints. 
        /// This helps to prevent overshoot. 
        /// </summary> 
        public static readonly float MaxLinearCorrection = 0.2f; // 20 cm 

        /// <summary> 
        /// The maximum angular position correction used when solving constraints. 
        /// This helps to prevent overshoot. 
        /// </summary> 
        public static readonly float MaxAngularCorrection = 8.0f / 180.0f * b2_pi; // 8 degrees 

        /// <summary> 
        /// The maximum linear velocity of a body. This limit is very large and is used 
        /// to prevent numerical problems. You shouldn't need to adjust this. 
        /// </summary> 
        public static readonly float MaxTranslation = 2.0f;
        public static readonly float MaxTranslationSquared = (MaxTranslation * MaxTranslation);

        /// <summary> 
        /// The maximum angular velocity of a body. This limit is very large and is used 
        /// to prevent numerical problems. You shouldn't need to adjust this. 
        /// </summary> 
        public static readonly float MaxRotation = (0.5f * b2_pi);
        public static readonly float MaxRotationSquared = (MaxRotation * MaxRotation);

        /// <summary> 
        /// This scale factor controls how fast overlap is resolved. Ideally this would be 1 so 
        /// that overlap is removed in one time step. However using values close to 1 often lead to overshoot. 
        /// </summary> 
        public static readonly float ContactBaumgarte = 0.2f;

        /// <summary> 
        /// The time that a body must be still before it will go to sleep. 
        /// </summary> 
        public static readonly float TimeToSleep = 0.5f; // half a second 

        /// <summary> 
        /// A body cannot sleep if its linear velocity is above this tolerance. 
        /// </summary> 
        public static readonly float LinearSleepTolerance = 0.01f; // 1 cm/s 

        /// <summary> 
        /// A body cannot sleep if its angular velocity is above this tolerance. 
        /// </summary> 
        public static readonly float AngularSleepTolerance = 2.0f / 180.0f * b2_pi; // 2 degrees/s 


        /// <summary> 
        /// Friction mixing law. Feel free to customize this. 
        /// </summary> 
        public static float MixFriction(float friction1, float friction2)
        {
            return (float)System.Math.Sqrt(friction1 * friction2);
        }

        /// <summary> 
        /// Restitution mixing law. Feel free to customize this. 
        /// </summary> 
        public static float MixRestitution(float restitution1, float restitution2)
        {
            return restitution1 > restitution2 ? restitution1 : restitution2;
        } 
     
        
    }
}
